package com.backstage.service.impl;

import com.backstage.dao.ScopeMapper;
import com.backstage.pojo.Scope;
import com.backstage.pojo.User;
import com.backstage.service.ScopeService;
import com.backstage.utils.PageBean;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ScopeServiceImpl implements ScopeService {
    @Autowired
    private ScopeMapper scopeMapper;

    public int selectScopeTotal(){
        return scopeMapper.selectScopeTotal();
    }

    public int selectInsertNewScope(Scope record){
        return scopeMapper.insert(record);
    }

    //获取用户列表，带搜索分页
    public PageBean<Scope> selectScopeList(int pageNum, int pageSize, int itemName){

        PageBean<Scope> pageBean = new PageBean<Scope>();
        Scope scopes = new Scope();
        if(!"".equals(itemName)){
            scopes.setScopeid(itemName);
        }
        PageHelper.startPage(pageNum,pageSize);
        List<Scope> scopeList = scopeMapper.selectScopeList(scopes);
        PageInfo<Scope> goodsPageInfo = new PageInfo<Scope>(scopeList);

        pageBean.setList(scopeList);
        pageBean.setPageBeanObj(goodsPageInfo.getPageNum(),goodsPageInfo.getPageSize(),goodsPageInfo.getNextPage(),goodsPageInfo.getPrePage(),goodsPageInfo.getTotal(),goodsPageInfo.getPages());

        return pageBean;

    }

}
